<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Model\Comcheck;

class WordController extends Controller
{
    /*word文档管理*/
    public function index(Request $request)
    {
    	/*获取文档列表*/
    	$name = $request->input("name");
		$comcheck_obj = new Comcheck();
		$list = $comcheck_obj->getCheckss($name);
    	$list = json_decode(json_encode($list), true);

    	$data = array();
    	foreach ($list as $key => $value) {
    		$word_arr = explode(",", $value['wordsUrl']);
    		$tmp_arr = array();
    		foreach($word_arr as $k=>$v) {
    			/*处理文档名称*/
    			preg_match("/^(\.\/storage\/word\/)[0-9]{8}\//i",$v, $matches);
    			$front = '';
    			if(!empty($matches)) {
    				$front = $matches[0];
    			}
    			$after = '';
	            preg_match("/\_[0-9]{12}\.docx$/i", $v, $matches);
	            if(!empty($matches)) {
	            	$after = $matches[0];
	            }
	            $word_name = str_replace(array($front, $after), '', $v);
    			$tmp_arr[$k]['name'] = $word_name;
    			$tmp_arr[$k]['url'] = trim($v,'.');
    			$tmp_arr[$k]['checkId'] = $value['checkId'];
    			if(!empty($value['updated'])) {
    				$tmp_arr[$k]['create_time'] = date('Y-m-d H:i:s',$value['updated']);
    			} else {
    				$tmp_arr[$k]['create_time'] = $value['created'];
    			}
    		}
    		$data = array_merge($data,$tmp_arr);
    	}
    	return view('admin.word.index',[
    		'name' => $name,
    		'data' => $data
    	]);
    }
}
